<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html"/>

  <xsl:template match="/">
    <xsl:apply-templates select="/cruisecontrol/build/*[local-name()='LoadTestCustomResults']" />
  </xsl:template>

  <xsl:template match="/cruisecontrol/build/*[local-name()='LoadTestCustomResults']">
    <p />
    <table border="1" cellSpacing="0" cellPadding="5" >
      <thead style="text-align: center;">
        <td>Name</td>
        <td>Run #</td>
        <td>Outcome</td>
        <td style="background-color: darkblue; color: white;">Duration</td>
        <td>Comment</td>
      </thead>
      <tr>
        <td>
          <xsl:value-of select="@Name"/>
        </td>
        <td>
          <xsl:value-of select="@LoadTestRunId"/>
        </td>
        <td>
          <xsl:choose>
            <xsl:when test="@Outcome ='Completed'">
              <span style="color: forestGreen; font-weight: bold;">
                <xsl:value-of select="@Outcome" />
              </span>
            </xsl:when>
            <xsl:otherwise>
              <span style="color: Red; font-weight: bold;">
                <xsl:value-of select="@Outcome" />
              </span>
            </xsl:otherwise>
          </xsl:choose>
        </td>
        <td>
          <xsl:value-of select="@Duration"/>
        </td>
        <td>
          <xsl:value-of select="@Comment"/>
        </td>
      </tr>
    </table>

    <h2>
      Transactions
    </h2>
    <xsl:apply-templates select="*[local-name()='Transactions']">
    </xsl:apply-templates>

    <h2>
      Test Results
    </h2>
    <xsl:apply-templates select="*[local-name()='Results']">
    </xsl:apply-templates>

    <h2>
      Exceptions
    </h2>
    <xsl:apply-templates select="*[local-name()='Exceptions']">
    </xsl:apply-templates>

  </xsl:template>

  <xsl:template match="*[local-name()='Transactions']">
    <table border="1" cellSpacing="0" cellPadding="5" >
      <thead style="text-align: center;">
        <td>Name</td>
        <td>Runs</td>
        <td>Minimum</td>
        <td>Average</td>
        <td>Maximum</td>
        <td style="border: burlywood">Percentile90"</td>
        <td style="border: burlywood; width: 70px">
          <xsl:value-of select="@CompTitile1"/>
        </td>
        <td style="border: burlywood; width: 70px">
          <xsl:value-of select="@CompTitile2"/>
        </td>
        <td style="border: burlywood; width: 70px">
          <xsl:value-of select="@CompTitile3"/>
        </td>
        <td style="border: burlywood; width: 70px">
          <xsl:value-of select="@CompTitile4"/>
        </td>
        <td style="border: burlywood; width: 70px">
          <xsl:value-of select="@CompTitile5"/>
        </td>
      </thead>
      <xsl:apply-templates select="./*" />
    </table>
  </xsl:template>

  <xsl:template match="*[local-name()='Transaction']">
    <tr>
      <td>
        <xsl:value-of select="@Name"/>
      </td>
      <td>
        <xsl:value-of select="@Runs"/>
      </td>
      <td>
        <xsl:value-of select="@Minimum"/>
      </td>
      <td>
        <xsl:value-of select="@Average"/>
      </td>
      <td>
        <xsl:value-of select="@Maximum"/>
      </td>
      <td style="border: burlywood">
        <xsl:value-of select="@Percentile90"/>
      </td>
      <td style="border: burlywood">
        <xsl:choose>
          <xsl:when test="@CompStatus1 = 'true'">
            <span style="color: forestGreen; font-weight: bold;">
              <xsl:value-of select="@CompValue1"/>
            </span>
          </xsl:when>
          <xsl:otherwise>
            <span style="color: Red; font-weight: bold;">
              <xsl:value-of select="@CompValue1"/>
            </span>
          </xsl:otherwise>
        </xsl:choose>
      </td>
      <td style="border: burlywood">
        <xsl:choose>
          <xsl:when test="@CompStatus2 = 'true'">
            <span style="color: forestGreen; font-weight: bold;">
              <xsl:value-of select="@CompValue2"/>
            </span>
          </xsl:when>
          <xsl:otherwise>
            <span style="color: Red; font-weight: bold;">
              <xsl:value-of select="@CompValue2"/>
            </span>
          </xsl:otherwise>
        </xsl:choose>
      </td>
      <td style="border: burlywood">
        <xsl:choose>
          <xsl:when test="@CompStatus3 = 'true'">
            <span style="color: forestGreen; font-weight: bold;">
              <xsl:value-of select="@CompValue3"/>
            </span>
          </xsl:when>
          <xsl:otherwise>
            <span style="color: Red; font-weight: bold;">
              <xsl:value-of select="@CompValue3"/>
            </span>
          </xsl:otherwise>
        </xsl:choose>
      </td>
      <td style="border: burlywood">
        <xsl:choose>
          <xsl:when test="@CompStatus4 = 'true'">
            <span style="color: forestGreen; font-weight: bold;">
              <xsl:value-of select="@CompValue4"/>
            </span>
          </xsl:when>
          <xsl:otherwise>
            <span style="color: Red; font-weight: bold;">
              <xsl:value-of select="@CompValue4"/>
            </span>
          </xsl:otherwise>
        </xsl:choose>
      </td>
      <td style="border: burlywood">
        <xsl:choose>
          <xsl:when test="@CompStatus5 = 'true'">
            <span style="color: forestGreen; font-weight: bold;">
              <xsl:value-of select="@CompValue5"/>
            </span>
          </xsl:when>
          <xsl:otherwise>
            <span style="color: Red; font-weight: bold;">
              <xsl:value-of select="@CompValue5"/>
            </span>
          </xsl:otherwise>
        </xsl:choose>
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="*[local-name()='Results']">
    <table border="1" cellSpacing="0" cellPadding="5" >
      <thead style="text-align: center;">
        <td>Name</td>
        <td>Total</td>
        <td style="background-color: fireBrick; color: white;">Failed</td>
        <td style="background-color: darkblue; color: white;">Duration</td>
      </thead>
      <xsl:apply-templates select="./*" />
    </table>
  </xsl:template>

  <xsl:template match="*[local-name()='Result']">
    <tr>
      <td>
        <xsl:value-of select="@TestCaseName"/>
      </td>
      <td>
        <xsl:value-of select="@Runs"/>
      </td>
      <td>
        <xsl:value-of select="@Errors"/>
      </td>
      <td>
        <xsl:value-of select="@Average"/>
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="*[local-name()='Exceptions']">
    <table border="1" cellSpacing="0" cellPadding="5" >
      <thead style="text-align: center;">
        <td>Test Name</td>
        <td style="background-color: fireBrick; color: white;">Exception</td>
      </thead>
      <xsl:apply-templates select="./*" />
    </table>
  </xsl:template>

  <xsl:template match="*[local-name()='Exception']">
    <tr>
      <td>
        <xsl:value-of select="@TestCaseName"/>
      </td>
      <td colspan="4" bgcolor="#FF9900">
        <b>
          <xsl:value-of select="@MessageText"/>
        </b>
        <br />
        <xsl:value-of select="@StackTrace"/>
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet>

